import React from 'react';
import {Button} from 'antd';
import {connect} from 'react-redux';
import {action_change_memuTitle} from '../../redux/action.js';
class Login extends React.Component{
    constructor(props){
        super(props);
    };
    componentWillMount(){
        console.log('login.jsx-componentWillMount');
    };
    componentDidMount(){
        console.log('login.jsx-componentDidMount');
    };
    componentWillUpdate(){
        console.log('login.jsx--state.getState()componentWillUpdate');
    };
    componentDidUpdate(){
        console.log('login.jsx--state.getState()componentDidpdate');
    };    
    goBack(){
        this.props.history.goBack();
    };
    setMenuTitle(){
        this.props._change_menuTitle('登录页');
    };
    render(){
        console.log('login.jsx-render');
        let {menuTitle,_change_menuTitle}=this.props;
        return (
            <div>
                <Button type="primary" onClick={()=>{this.goBack()}}>返回</Button>
                <p><Button type="default" onClick={()=>{this.setMenuTitle()}}>设置标题</Button><span>{menuTitle}</span></p>
            </div>
        )
    }
};

let mapStateToProps=(state,myownProps)=>{
    return {
        menuTitle:state.memuTitleReducer.menuTitle
    }
};

let mapDispatchToProps=(dispatch,myownProps)=>{
    return {
        _change_menuTitle:(newTitle)=>{
            dispatch(action_change_memuTitle(newTitle))
        }
    }
}

export default connect(mapStateToProps,mapDispatchToProps)(Login) 


